package com.yoomiito.app.widget.dialog;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.jakewharton.rxbinding3.view.RxView;
import com.yoomiito.app.R;
import com.yoomiito.app.model.bean.AppInterfaceInfo;
import com.yoomiito.app.model.bean.GoodsDetail;
import com.yoomiito.app.net.YmApi;
import com.yoomiito.app.utils.AllUtils;
import com.yoomiito.app.utils.ImageLoader;
import com.yoomiito.app.utils.SpannableUtils;
import com.yoomiito.app.utils.YMToast;
import com.yoomiito.app.utils.wx.WXUtils;
import com.yoomiito.app.widget.NumControlView;
import com.yoomiito.app.widget.OnNumberChangeListener;
import com.yoomiito.app.widget.SelectView;

import java.util.concurrent.TimeUnit;

import chihane.jdaddressselector.AddressSelector;
import cn.droidlover.xdroidmvp.net.ApiException;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.BaseModel;
import cn.droidlover.xdroidmvp.net.XApi;

public class ShopCarDialog extends BaseDialog implements View.OnClickListener {
    private OnResultListener mOnResultListener;

    AppInterfaceInfo goodsDetail;
    int nnum = 1;

    public ShopCarDialog(@NonNull Context context, AppInterfaceInfo goodsDetail) {
        this(context, 0);
        this.goodsDetail = goodsDetail;
    }

    public ShopCarDialog(@NonNull Context context, int themeResId) {
        super(context, R.style.dialog_2);
    }

    @Override
    public View setView() {

        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_shop_car, null, false);
        ImageView roundImageView = view.findViewById(R.id.item_order_goods_iv);
        ImageLoader.getInstance().into(mContext, goodsDetail.banner, roundImageView);
        view.findViewById(R.id.btn_pick).setOnClickListener(this);
        TextView textView = view.findViewById(R.id.item_order_goods_title);
        textView.setText(goodsDetail.productName);
        TextView textView1 = view.findViewById(R.id.item_order_goods_title1);
        textView1.setText(goodsDetail.point);
        TextView textView2 = view.findViewById(R.id.item_order_goods_price);
        textView2.setText("¥" + goodsDetail.salePrice);
        NumControlView numControlView = view.findViewById(R.id.num_control_view);
        numControlView.setStep(goodsDetail.againStep);
        numControlView.setMin(goodsDetail.againNum);
        numControlView.setNum(goodsDetail.againNum);
        nnum = numControlView.getNum();
        numControlView.setListener(new OnNumberChangeListener() {
            @Override
            public void numberChange(int num) {
                nnum = num;
            }
        });
        setWidthPercent(1);
        setmHeightPercent(0.4);
        setmGravity(Gravity.BOTTOM);
        return view;
    }

    @Override
    public void onBackPressed() {

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_pick:
                if (AllUtils.isFastClick()) {
                    return;
                }
                mOnResultListener.onResult(nnum);
                dismiss();
                break;
        }
    }

    public void setOnResultListener(OnResultListener onResultListener) {
        mOnResultListener = onResultListener;
    }

    public interface OnResultListener {
        void onResult(int num);
    }

}
